import {baseUrl} from './env';
import axios from 'axios';

export default async(url='',data={},type='GET')=>{
  type=type.toUpperCase();
  if(type==='POST'){
    if(!data){
      return await axios.post(baseUrl+url)
    }else{
      return await axios.post(baseUrl+url,data);
    }
  }else if(type==='GET'){
      let dataStr='';
      Object.keys(data).forEach(key=>{
        dataStr+=key+'='+data[key]+'&'
      })
      return await axios.get(baseUrl+url+'?'+dataStr);
  }
}